from collections import defaultdict, deque

def main():
    N, M = map(int, input().split())
    out_degree = defaultdict(list)
    in_degree = [0] * N
    for i in range(M):
        s, t = map(int, input().split())
        out_degree[s].append(t)
        in_degree[t] += 1
    
    queue = deque()
    for i in range(N):
        if in_degree[i] == 0:
            queue.append(i)
    
    res = []
    while queue:
        node = queue.popleft()
        res.append(node)
        
        for i in out_degree[node]:
            in_degree[i] -= 1
            if in_degree[i] == 0:
                queue.append(i)
    
    if len(res) < N:
        print(-1)
    else:
        print(' '.join(map(str, res)))
        
main()